# Generated by Django 2.2.12 on 2020-05-05 14:20
from django.db import migrations
from django.utils.translation import gettext_lazy as _

USERSTATUS_DELETED = 99


def remove_email_from_deleted_users(apps, schema_editor):
    User = apps.get_model("auth", "User")
    for user in User.objects.filter(profile__status=USERSTATUS_DELETED):
        email_comment = _("Email avant suppression: %s") % user.email
        user.email = ""
        user.save()
        user.profile.comments = (
            f"{user.profile.comments}\n{email_comment}"
            if user.profile.comments
            else email_comment
        )
        user.profile.save()


class Migration(migrations.Migration):
    dependencies = [
        ("user", "0054_timesheet_editor_perm"),
    ]

    operations = [
        migrations.RunPython(remove_email_from_deleted_users, migrations.RunPython.noop)
    ]
